package net.huashitong.Project.service;

import com.sirdc.modules.core.exceptions.SystemException;
import com.sirdc.modules.core.filter.Paging;
import com.sirdc.modules.sys.filter.NodeNewschedulesModel;
import com.sirdc.modules.sys.service.PlanTimeReckonService;
import com.sirdc.modules.utils.NumberUtils;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Project.entity.EarlyWarningNode;
import net.huashitong.Project.entity.NewProjects;
import net.huashitong.Project.filter.NewProjectsFilter;
import net.huashitong.Project.responseModel.MailListDataModel;
import net.huashitong.Project.responseModel.NewProjectDataModel;
import net.huashitong.Project.responseModel.NodeNewschedulesDataModel;
import net.huashitong.Project.util.Dto2Entity;
import net.huashitong.node.entity.NodeNewschedules;
import net.huashitong.node.filter.NodeNewschedulesFilter;
import net.huashitong.node.service.NodeNewschedulesService;
import net.huashitong.oversee.databean.DepartRank;
import net.huashitong.oversee.entity.GradePoint;
import net.huashitong.oversee.entity.ScoreSummary;
import net.huashitong.oversee.entity.ScoreSummaryTemp;
import net.huashitong.oversee.entity.SupervisionTask;
import net.huashitong.oversee.filter.GradePointFilter;
import net.huashitong.oversee.filter.ScoreSummaryFilter;
import net.huashitong.oversee.filter.SupervisionTaskFilter;
import net.huashitong.oversee.service.GradePointService;
import net.huashitong.oversee.service.ScoreSummaryService;
import net.huashitong.oversee.service.ScoreSummaryTempService;
import net.huashitong.oversee.service.SupervisionTaskService;
import net.huashitong.taskGroup.databean.*;
import net.huashitong.user.databean.BnpUserDatabean;
import net.huashitong.user.databean.OnLineDatabean;
import net.huashitong.user.entity.BnpUser;
import net.huashitong.user.entity.Message;
import net.huashitong.user.filter.BnpUserFilter;
import net.huashitong.user.filter.MessageFilter;
import net.huashitong.user.filter.OnlineFilter;
import net.huashitong.user.service.BnpUserService;
import net.huashitong.user.service.LoginLogService;
import net.huashitong.user.service.MessageService;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.*;

@Service
public class ExportService {


    @Autowired
    private BnpUserService bnpUserService;
    @Autowired
    private NodeNewschedulesService nns;
    @Autowired
    private NewProjectsService newProjectsService;
    @Autowired
    private EarlyWarningNodeService earlyWarningNodeService;
    @Autowired
    private PlanTimeReckonService planTimeReckonService;
    @Autowired
    private LoginLogService loginLogService;
    @Autowired
    private GradePointService gradePointService;
    @Autowired
    private ScoreSummaryService scoreSummaryService;
    @Autowired
    private ScoreSummaryTempService tempService;
    @Autowired
    private SupervisionTaskService taskService;
    @Autowired
    private MessageService messageService;


    /**
     * -
     * -----------------通讯录导出功能--------------
     *
     * @param filter
     * @return
     */
    public HSSFWorkbook getExcelMailListData(BnpUserFilter filter, List<String> heads) {
        //查询用户单位、角色
        List<BnpUser> userList = bnpUserService.getUserInfoUsePage(filter);
        HSSFWorkbook wb = new HSSFWorkbook();//创建一个对应Excel文件
        HSSFSheet sheet = wb.createSheet("通讯录"); //床建excel 中的sheet
        HSSFRow row = sheet.createRow(0);
        sheet.autoSizeColumn(1, true);

        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式
        style.setFillForegroundColor((short) 13);// 设置背景色
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        //row.setHeight((short) 900);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        //------列-------
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(1, 1, 0, 0);
        sheet.addMergedRegion(cellRangeAddress0);
        HSSFCell cell1 = row.createCell(0);
        cell1.setCellValue("序号");
        cell1.setCellStyle(style);

        for (int i = 0; i < heads.size(); i++) {
            HSSFCell cell2 = row.createCell(i + 1);
            cell2.setCellValue(AddressHeaders.getValues(heads.get(i)).getValue());
            cell2.setCellStyle(style);
//            sheet.autoSizeColumn((short)i);
//            sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 17 / 10);
//            sheet.setColumnWidth(i + 1, 20 * 512);
        }

        String branch = "";
        String role = "";
        String name = "";
        String phone = "";
        String branchType = "";
        int rows = 0;
        //单位、角色、姓名、联系电话
        for (int i = 0; i < userList.size(); i++) {
            BnpUser bnpUser = new BnpUser();
            bnpUser = (BnpUser) Dto2Entity.populate(userList.get(i), bnpUser);
            branch = bnpUser.getBranch();
            branchType = bnpUser.getBranchType();
            role = bnpUser.getRole();
            name = bnpUser.getName();
            phone = bnpUser.getPhone();
            if (name.length() > 4) {
                continue;
            } else {
                rows++;
            }
            if ("0".equals(branchType)) {
                role = "业主单位" + role;
            }
            if ("1".equals(branchType)) {
                role = "审批部门" + role;
            }
            row = sheet.createRow(rows);
            row.createCell(0).setCellValue(rows);

            for (int j = 0; j < heads.size(); j++) {
                if ("branch".equals(AddressHeaders.getValues(heads.get(j)).getCode()))
                    row.createCell(j + 1).setCellValue(branch);
                if ("role".equals(AddressHeaders.getValues(heads.get(j)).getCode()))
                    row.createCell(j + 1).setCellValue(role);
                if ("userName".equals(AddressHeaders.getValues(heads.get(j)).getCode()))
                    row.createCell(j + 1).setCellValue(name);
                if ("phone".equals(AddressHeaders.getValues(heads.get(j)).getCode()))
                    row.createCell(j + 1).setCellValue(phone);
                sheet.autoSizeColumn((short) j);
                sheet.setColumnWidth(j, sheet.getColumnWidth(j) * 15 / 10);

            }

        }
        return wb;
    }

    /**
     * ------------------用户登录次数导出功能-----------
     *
     * @return
     */
    public HSSFWorkbook getExcelOnLineListData(OnlineFilter filter) {
        //查询用户单位、角色
        List<OnLineDatabean> onLineList = loginLogService.queryUserOnLineCount(filter);

        //统计进行中的节点
        for (OnLineDatabean bean : onLineList) {

            //进行中的节点
            filter.setName(bean.getName());
            BigInteger progressNodes = nns.queryProgressNodesCountByFilter(filter);
            bean.setProgressNodes(progressNodes + "");
        }


        if (onLineList.isEmpty()) {
            throw new SystemException("没有数据");
        }
        HSSFWorkbook wb = new HSSFWorkbook();//创建一个对应Excel文件
        HSSFSheet sheet = wb.createSheet("用户登录次数"); //床建excel 中的sheet
        HSSFRow row = sheet.createRow(0);
        sheet.autoSizeColumn(1, true);

        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式
        style.setFillForegroundColor((short) 13);// 设置背景色
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        //row.setHeight((short) 900);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        //------列-------
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(1, 1, 0, 0);
        sheet.addMergedRegion(cellRangeAddress0);
        HSSFCell cell1 = row.createCell(0);
        cell1.setCellValue("序号");
        cell1.setCellStyle(style);


        List<String> heads = filter.getExportHead();
        for (int i = 0; i < heads.size(); i++) {
            HSSFCell cell = row.createCell(i + 1);
            cell.setCellValue(LoginHeaders.getValues(heads.get(i)).getValue());
            cell.setCellStyle(style);
            sheet.autoSizeColumn((short) i);
            sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 15 / 10);
//            sheet.setColumnWidth(i + 1, 25 * 312);
        }

        String name = "";
        int rows = 0;
        //姓名、联系电话
        for (int i = 0; i < onLineList.size(); i++) {
            OnLineDatabean online = onLineList.get(i);
            name = online.getName();
            rows++;
            row = sheet.createRow(rows);
            row.createCell(0).setCellValue(rows);
            for (int m = 0; m < heads.size(); m++) {
                if ("userName".equals(LoginHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(name);
                if ("num".equals(LoginHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(online.getNum().toString());
                if ("rownum".equals(LoginHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(online.getRownum().toString());
                if ("branch".equals(LoginHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(online.getBranch());
                if ("role".equals(LoginHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(online.getRole());
                if ("progressNodes".equals(LoginHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(online.getProgressNodes());
                sheet.autoSizeColumn((short) m);
                sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 15 / 10);
            }
            /*row.createCell(1).setCellValue(name);
            row.createCell(2).setCellValue(online.getNum().toString());
            row.createCell(3).setCellValue(online.getRownum().toString());*/
        }
        return wb;
    }

    /**
     * 节点管理导出功能
     *
     * @param filter
     * @return
     */
    public HSSFWorkbook saveExcelNodeManageListData(NewProjectsFilter filter, List<String> heads) throws ParseException {
        //更新项目表的开工时间，封装所有项目
        List<NewProjects> projectLists = newProjectsService.query();
        Map<String, NewProjects> projectsMap = new HashMap<>();
        for (NewProjects projects1 : projectLists) {
            projectsMap.put(projects1.getSysId(), projects1);
        }
        List<NewProjects> updateNewprojects = new ArrayList<>();

        Paging page = new Paging();
        page.setSortCol("startTime");
        page.setSortVal("desc");
        page.setPageSize(1000);
        filter.setPaging(page);
        // List<NewProjects> newProjects = newProjectsService.getProjectInfoPage(filter);
        List<NewProjects> newProjects = newProjectsService.getProjects(filter.getSysids());
        List<String> allProjects = new ArrayList<>();

        for (NewProjects flag : newProjects) {
            allProjects.add(flag.getSysId());
        }
        //推算各个节点的时间
        List<NodeNewschedulesModel> list = iii(allProjects);
        //查询所有完成节点统计各节点的平均用时+++++++++++++++++++++++++++
        NodeNewschedulesFilter allFilter = new NodeNewschedulesFilter();
        allFilter.setStatus("2");
        List<NodeNewschedules> allList = nns.queryByFilter(allFilter);
        Map<String, Double> nodeTimeCountMap = new HashMap<>();
        Map<String, Integer> nodeCountMap = new HashMap<>();
        for (NodeNewschedules all : allList) {
            if (nodeTimeCountMap.containsKey(all.getNodeId())) {
                //节点次数加1
                int count = nodeCountMap.get(all.getNodeId()) + 1;
                nodeCountMap.put(all.getNodeId(), count);
                //节点时间总和
                String factTimeStr = StringUtils.isNotBlank(all.getFactTime()) ? all.getFactTime() : "0";
                double factTimeDou = Double.parseDouble(factTimeStr);
                double newFactTimeDou = nodeTimeCountMap.get(all.getNodeId()) + factTimeDou;
                nodeTimeCountMap.put(all.getNodeId(), newFactTimeDou);
            } else {
                nodeCountMap.put(all.getNodeId(), 1);
                String factTimeStr = StringUtils.isNotBlank(all.getFactTime()) ? all.getFactTime() : "0";
                double factTimeDou = Double.parseDouble(factTimeStr);
                nodeTimeCountMap.put(all.getNodeId(), factTimeDou);
            }
        }
        DecimalFormat df = new DecimalFormat("#.##");
        Map<String, String> avMap = new HashMap<>();
        Iterator<Map.Entry<String, Double>> it = nodeTimeCountMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Double> entry = it.next();
            int count = nodeCountMap.get(entry.getKey());
            double value = entry.getValue();
            double result = value / count;
            avMap.put(entry.getKey(), df.format(result));
        }
        //查询所有完成节点统计各节点的平均用时^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        Map<String, NewProjects> newProjectsMap = new HashMap<>();
        for (NewProjects n : newProjects) {
            if (!newProjectsMap.containsKey(n.getSysId())) {
                newProjectsMap.put(n.getSysId(), n);
            }
        }
        //封装项目预警情况
        Map<String, EarlyWarningNode> earlyMap = new HashMap<>();
        List<EarlyWarningNode> earlyWarningNodeList = earlyWarningNodeService.query();
        for (EarlyWarningNode e : earlyWarningNodeList) {
            if (!earlyMap.containsKey(e.getNodeSysId())) {
                earlyMap.put(e.getNodeSysId(), e);
            }
        }

        HSSFWorkbook wb = new HSSFWorkbook();//创建一个对应Excel文件
        HSSFSheet sheet = wb.createSheet("节点管理"); //床建excel 中的sheet
        HSSFRow row = sheet.createRow(0);
        sheet.autoSizeColumn(1, true);
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式
        style.setFillForegroundColor((short) 13);// 设置背景色
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        //row.setHeight((short) 900);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);


        //------列-------
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(1, 1, 0, 0);
        sheet.addMergedRegion(cellRangeAddress0);
        HSSFCell cell1 = row.createCell(0);
        cell1.setCellValue("序号");
        cell1.setCellStyle(style);
//        sheet.setColumnWidth(0, 15 * 112);
        if (ObjectUtils.isBlank(heads)) {
            return null;
        }
        for (int j = 0; j < heads.size(); j++) {
            HSSFCell cell = row.createCell(j + 1);

            cell.setCellValue(NodeHeaders.getValues(heads.get(j)).getValue()); //设置表头
            cell.setCellStyle(style);
            sheet.autoSizeColumn((short) j);
            sheet.setColumnWidth(j, sheet.getColumnWidth(j) * 15 / 10);
        }

        String projectName = "";
        String baseDetail = "";
        String nodeName = "";
        String planTime = "";
        //进行中
        String planBeginDate = "";
        //已完成
        String factTime = "";
        String factFinishDate = "";
        String avTime = "";         //节点平均用时
        String resUser = "";        //责任人
        String resUserPhone = "";    //责任人电话
        String operatorUser = "";   //经办人
        String operatorPhone = "";   //经办人电话
        String resDept = "";        //责任单位
        int rows = 0;
        String planEndTimeFlag = "";

        Map<String, String> resMap = new HashMap<>();

        for (int i = 0; i < list.size(); i++) {

            if (resMap.size() == 0) {
                resMap.put(list.get(i).getProjectId(), list.get(i).getProjectId());
            } else {
                //最后一个小节点
                if (!resMap.containsKey(list.get(i).getProjectId()) || i == list.size() - 1) {
                    rows++;
                    row = sheet.createRow(rows);
                    if(i == list.size() - 1){
                        NodeNewschedulesModel model = list.get(i);
                        planEndTimeFlag = model.getPlanEndTime();
                        factFinishDate = model.getFactFinishDate();
                    }

                    NewProjects newProjects1 = projectsMap.get(list.get(i - 1).getProjectId());
                    if (ObjectUtils.isBlank(newProjects1)) {
                        continue;
                    }

                    newProjects1.setStartTime(StringUtils.isBlank(planEndTimeFlag) ? factFinishDate : planEndTimeFlag);
                    updateNewprojects.add(newProjects1);

                    row.createCell(0).setCellValue(rows);
                    for (int m = 0; m < heads.size(); m++) {

                        //项目名称
                        if ("projectName".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue(projectName);
                        //节点id
                        if ("nodeId".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue(list.get(i).getNodeId());
                        //节点名称
                        if ("nodeNames".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue(nodeName);
                        //基本情况
                        if ("baseDetail".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //计划用时
                        if ("planTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //实际用时
                        if ("factTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //计划开始时间
                        if ("planBeginTime".equals(NodeHeaders.getValues(heads.get(m)).getCode())) //默认实际开始时间
                            row.createCell(m + 1).setCellValue(planEndTimeFlag);
                        //计划结束时间
                        if ("planEndTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //实际开始时间
                        if ("planBeginDate".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //实际结束时间
                        if ("factFinishDate".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue(factFinishDate);
                        //节点平均用时
                        if ("avTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //责任人
                        if ("resUser".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //责任人电话
                        if ("resUserPhone".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //经办人
                        if ("operatorUser".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //经办人电话
                        if ("operatorPhone".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //责任单位
                        if ("resDept".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //逾期天数
                        if ("earlyDays".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //发送短信次数
                        if ("messageNum".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        sheet.autoSizeColumn((short) m);
                        sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 15 / 10);
                    }
                    resMap.put(list.get(i).getProjectId(), list.get(i).getProjectId());
                }
                if (i == list.size()) {
                    rows++;
                    row = sheet.createRow(rows);

                    NewProjects newProjects1 = projectsMap.get(list.get(i).getProjectId());
                    newProjects1.setStartTime(planEndTimeFlag);
                    updateNewprojects.add(newProjects1);

                    row.createCell(0).setCellValue(rows);
                    for (int m = 0; m < heads.size(); m++) {

                        //项目名称
                        if ("projectName".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue(projectName);
                        //节点id
                        if ("nodeId".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue(list.get(i).getNodeId());
                        //节点名称
                        if ("nodeNames".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue(nodeName);
                        //基本情况
                        if ("baseDetail".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //计划用时
                        if ("planTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //实际用时
                        if ("factTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //计划开始时间
                        if ("planBeginTime".equals(NodeHeaders.getValues(heads.get(m)).getCode())) //默认实际开始时间
                            row.createCell(m + 1).setCellValue(planEndTimeFlag);
                        //计划结束时间
                        if ("planEndTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //实际开始时间
                        if ("planBeginDate".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue(factFinishDate);
                        //实际结束时间
                        if ("factFinishDate".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //节点平均用时
                        if ("avTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //责任人
                        if ("resUser".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //责任人电话
                        if ("resUserPhone".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //经办人
                        if ("operatorUser".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //经办人电话
                        if ("operatorPhone".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //责任单位
                        if ("resDept".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //逾期天数
                        if ("earlyDays".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        //发送短信次数
                        if ("messageNum".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                            row.createCell(m + 1).setCellValue("");
                        sheet.autoSizeColumn((short) m);
                        sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 15 / 10);
                    }
                }
            }
            if (!"1".equals(list.get(i).getState())) {    // 节点不确定
                continue;
            }
            projectName = newProjectsMap.get(list.get(i).getProjectId()).getName();
            nodeName = list.get(i).getNodeName();
            String status = list.get(i).getStatus();
            if ("0".equals(status)) {
                baseDetail = "未开始";
                planBeginDate = "";
                factTime = "0";
                factFinishDate = "";
            } else if ("1".equals(status)) {
                baseDetail = "进行中";
                planBeginDate = list.get(i).getPlanBeginDate();
                factTime = "0";
                factFinishDate = "";
            } else if ("2".equals(status)) {
                baseDetail = "已完成";
                planBeginDate = list.get(i).getPlanBeginDate();
                factTime = list.get(i).getFactTime();
                factFinishDate = list.get(i).getFactFinishDate();
            }
            planTime = list.get(i).getPlanTime();
            avTime = StringUtils.isNotBlank(avMap.get(list.get(i).getNodeId())) ? avMap.get(list.get(i).getNodeId()) : "";
            resUser = list.get(i).getResUser();
            resUserPhone = list.get(i).getResUserPhone();
            operatorUser = list.get(i).getOperatorUser();
            operatorPhone = list.get(i).getOperatorPhone();
            resDept = list.get(i).getResDept();
            EarlyWarningNode earlyWarningNode = earlyMap.get(list.get(i).getSysId());
            String earlyDays = "";      //逾期天数
            String messageNum = "";     //发送短信的次数

            if (ObjectUtils.isNotBlank(earlyWarningNode)) {
                //未处理的预警信息
                if ("0".equals(earlyWarningNode.getState())) {
                    earlyDays = earlyWarningNode.getNumber();
                    messageNum = earlyWarningNode.getMessageMumber();
                } else {
                    earlyDays = "";
                    messageNum = "";
                }
            }
            rows++;
            row = sheet.createRow(rows);
            String planBeginTime = "";
            String planEndTime = "";
            if (list.get(i).getNodeId().contains("23") || list.get(i).getNodeId().contains("24")) {
                planBeginTime = "";
                planEndTime = "";
            } else {
                planBeginTime = list.get(i).getPlanBeginTime();
                planEndTime = list.get(i).getPlanEndTime();
            }
            planEndTimeFlag = planEndTime;


            row.createCell(0).setCellValue(rows);

            for (int m = 0; m < heads.size(); m++) {

                //项目名称
                if ("projectName".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(projectName);
                //节点id
                if ("nodeId".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(list.get(i).getNodeId());
                //节点名称
                if ("nodeNames".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(nodeName);
                //基本情况
                if ("baseDetail".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(baseDetail);
                //计划用时
                if ("planTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(planTime);
                //实际用时
                if ("factTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(factTime);
                //计划开始时间
                if ("planBeginTime".equals(NodeHeaders.getValues(heads.get(m)).getCode())) //默认实际开始时间
                    row.createCell(m + 1).setCellValue(planBeginTime);
                //计划结束时间
                if ("planEndTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(planEndTime);
                //实际开始时间
                if ("planBeginDate".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(planBeginDate);
                //实际结束时间
                if ("factFinishDate".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(factFinishDate);
                //节点平均用时
                if ("avTime".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(avTime);
                //责任人
                if ("resUser".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(resUser);
                //责任人电话
                if ("resUserPhone".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(resUserPhone);
                //经办人
                if ("operatorUser".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(operatorUser);
                //经办人电话
                if ("operatorPhone".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(operatorPhone);
                //责任单位
                if ("resDept".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(resDept);
                //逾期天数
                if ("earlyDays".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(earlyDays);
                //发送短信次数
                if ("messageNum".equals(NodeHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(messageNum);
                sheet.autoSizeColumn((short) m);
                sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 15 / 10);
            }
        }
        newProjectsService.batchUpdate(updateNewprojects);
        return wb;
    }


    /**
     * 项目管理导出功能
     *
     * @param filter
     * @return
     */
    public HSSFWorkbook getExcelProjectManageListData(NewProjectsFilter filter, List<String> heads) {

        Paging page = new Paging();
        page.setSortCol("startTime");
        page.setSortVal("desc");
        page.setPageSize(300);
        filter.setPaging(page);

        List<NewProjects> newProjects;
//         List<NewProjects> newProjects = newProjectsService.getProjectInfoPage(filter);
        if (ObjectUtils.isBlank(filter.getSysids())) {
            newProjects = newProjectsService.getProjectsInfo(filter);
        } else {
            newProjects = newProjectsService.getProjects(filter.getSysids());
        }
//        List<NewProjects> newProjects = newProjectsService.getProjects(filter.getSysids());
        HSSFWorkbook wb = new HSSFWorkbook();//创建一个对应Excel文件
        HSSFSheet sheet = wb.createSheet("项目管理"); //床建excel 中的sheet
        HSSFRow row = sheet.createRow(0);

        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式
        style.setFillForegroundColor((short) 13);// 设置背景色
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        //row.setHeight((short) 900);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        //------列-------
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(1, 1, 0, 0);
        sheet.addMergedRegion(cellRangeAddress0);
        HSSFCell cell1 = row.createCell(0);
        cell1.setCellValue("序号");
        cell1.setCellStyle(style);

        for (int i = 0; i < heads.size(); i++) {
            HSSFCell cell = row.createCell(i + 1);
            cell.setCellValue(ProjectHeaders.getValues(heads.get(i)).getValue());  //设置表头
            cell.setCellStyle(style);
            sheet.autoSizeColumn((short) i);
            sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 15 / 10);
        }

        String projectName = "";            //项目名称
        String describes = "";             //基本情况
        String natureType = "";             //行业类别
        String startTime = "";              //开工时间
        String resDept = "";                //责任单位
        String ownerUnitPerson = "";         //负责人
        String ownerUnitPersonPhone = "";    //负责人电话
        String contactName = "";            //经办人
        String contactPhone = "";           //经办人电话
        String resUser = "";                //分管县领导
        String resPhone = "";               //分管县领导电话
        String address = "";                //项目地址
        String status = "";                 //进展情况
        String overdueNode = "";            //逾期节点
        String overSeeDeatil = "";          //督查情况
        int rows = 0;
        for (int i = 0; i < newProjects.size(); i++) {
            projectName = newProjects.get(i).getName();            //项目名称
            describes = newProjects.get(i).getDescribes();             //基本情况
            String flag = newProjects.get(i).getNatureType();             //行业类别
            if ("0".equals(flag)) {
                natureType = "政府投资类";
            }
            if ("1".equals(flag)) {
                natureType = "企业投资类";
            }
            if ("2".equals(flag)) {
                natureType = "土地收储类";
            }
            if ("3".equals(flag)) {
                natureType = "政府投资房建市政类";
            }
            if ("4".equals(flag)) {
                natureType = "政府投资交通水利类";
            }
            String flag1 = newProjects.get(i).getStatus();              //开工时间
            if ("4".equals(flag1)) {
                startTime = "已完成";
            } else {
                startTime = newProjects.get(i).getStartTime();
            }
            resDept = newProjects.get(i).getResDept();                          //责任单位
            ownerUnitPerson = newProjects.get(i).getOwnerUnitPerson();           //负责人
            ownerUnitPersonPhone = newProjects.get(i).getOwnerUnitPersonPhone();    //负责人电话
            contactName = newProjects.get(i).getContactName();              //经办人
            contactPhone = newProjects.get(i).getContactPhone();            //经办人电话
            resUser = newProjects.get(i).getResUser();                      //分管县领导
            resPhone = newProjects.get(i).getResPhone();                    //分管县领导电话
            address = newProjects.get(i).getAddress();                      //项目地址
            String flag2 = newProjects.get(i).getStatus();                        //进展情况
            overdueNode = "";           //逾期节点
            overSeeDeatil = "";          //督查情况
            if ("0".equals(flag2)) {
                status = "项目创建成功";
            }
            if ("1".equals(flag2)) {
                status = "部门确认阶段";
            }
            if ("2".equals(flag2)) {
                status = "业主确认阶段";
            }
            if ("3".equals(flag2)) {
                status = "攻坚办审核，项目转进行中";
            }
            if ("4".equals(flag2)) {
                status = "项目审核完成";
            }

            rows++;
            row = sheet.createRow(rows);
            row.createCell(0).setCellValue(rows);
            for (int m = 0; m < heads.size(); m++) {

                if ("projectName".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(projectName);

                if ("describes".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(describes);

                if ("natureType".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(natureType);

                if ("startTime".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(startTime);

                if ("resDept".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(resDept);

                if ("ownerUnitPerson".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(ownerUnitPerson);

                if ("ownerUnitPersonPhone".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(ownerUnitPersonPhone);

                if ("contactName".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(contactName);

                if ("contactPhone".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(contactPhone);

                if ("resUser".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(resUser);

                if ("resPhone".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(resPhone);

                if ("address".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(address);

                if ("status".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(status);

                if ("overdueNode".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(overdueNode);

                if ("overSeeDeatil".equals(ProjectHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(overSeeDeatil);
                int colWidth = sheet.getColumnWidth(m) * 2;
                if (colWidth < 200 * 200) {
                    sheet.autoSizeColumn((short) m);
                    sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 12 / 10);
                } else {
                    sheet.setColumnWidth(m, 20000);
                }
            }

        }
        return wb;
    }

    public List<MailListDataModel> queryMailListData(BnpUserFilter filter) {
        List<MailListDataModel> resultList = new ArrayList<>();
        //查询用户单位、角色
        List<BnpUser> userList = bnpUserService.getUserInfoUsePage(filter);
        String branch = "";
        String role = "";
        String name = "";
        String phone = "";
        String branchType = "";
        String sysId = "";
        int rows = 0;
        //单位、角色、姓名、联系电话
        for (int i = 0; i < userList.size(); i++) {
            MailListDataModel mailListDataModel = new MailListDataModel();
            BnpUser bnpUser = new BnpUser();
            bnpUser = (BnpUser) Dto2Entity.populate(userList.get(i), bnpUser);
            branch = bnpUser.getBranch();
            branchType = bnpUser.getBranchType();
            role = bnpUser.getRole();
            name = bnpUser.getName();
            phone = bnpUser.getPhone();
            sysId = bnpUser.getSysId();
            rows++;
            if ("0".equals(branchType)) {
                role = "业主单位" + role;
            }
            if ("1".equals(branchType)) {
                role = "审批部门" + role;
            }
            mailListDataModel.setBranch(branch);
            mailListDataModel.setName(name);
            mailListDataModel.setPhone(phone);
            mailListDataModel.setRole(role);
            mailListDataModel.setSysId(sysId);
            resultList.add(mailListDataModel);
        }
        return resultList;
    }

    public List<NodeNewschedulesDataModel> queryNodeNewschedulesData(NodeNewschedulesFilter filter) {
        List<String> projectIds = new ArrayList<>();
        if (StringUtils.isNotBlank(filter.getProjectName())) {
            NewProjectsFilter newProjectsFilter = new NewProjectsFilter();
            newProjectsFilter.setName(filter.getProjectName());
            List<NewProjects> newProjects = newProjectsService.getProjectInfo(newProjectsFilter);
            for (NewProjects newp : newProjects) {
                projectIds.add(newp.getSysId());
            }
            filter.setProjectIds(projectIds);
        }
        if (StringUtils.isNotBlank(filter.getBaseDetail())) {
            if ("3".equals(filter.getBaseDetail())) {
                filter.setState("0");
            } else {
                if ("4".equals(filter.getBaseDetail())) {
                    filter.setState("2");
                } else {
                    filter.setState("1");
                    filter.setStatus(filter.getBaseDetail());
                }
            }
        }
        List<NodeNewschedules> list = nns.queryByFilter(filter);
        //查询所有完成节点统计各节点的平均用时
        NodeNewschedulesFilter allFilter = new NodeNewschedulesFilter();
        allFilter.setStatus("2");
        List<NodeNewschedules> allList = nns.queryByFilter(allFilter);
        Map<String, Double> nodeTimeCountMap = new HashMap<>();
        Map<String, Integer> nodeCountMap = new HashMap<>();
        for (NodeNewschedules all : allList) {
            if (nodeTimeCountMap.containsKey(all.getNodeId())) {
                //节点次数加1
                int count = nodeCountMap.get(all.getNodeId()) + 1;
                nodeCountMap.put(all.getNodeId(), count);
                //节点时间总和
                String factTimeStr = StringUtils.isNotBlank(all.getFactTime()) ? all.getFactTime() : "0";
                double factTimeDou = Double.parseDouble(factTimeStr);
                double newFactTimeDou = nodeTimeCountMap.get(all.getNodeId()) + factTimeDou;
                nodeTimeCountMap.put(all.getNodeId(), newFactTimeDou);
            } else {
                nodeCountMap.put(all.getNodeId(), 1);
                String factTimeStr = StringUtils.isNotBlank(all.getFactTime()) ? all.getFactTime() : "0";
                double factTimeDou = Double.parseDouble(factTimeStr);
                nodeTimeCountMap.put(all.getNodeId(), factTimeDou);
            }
        }
        DecimalFormat df = new DecimalFormat("#.##");
        Map<String, String> avMap = new HashMap<>();
        Iterator<Map.Entry<String, Double>> it = nodeTimeCountMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Double> entry = it.next();
            int count = nodeCountMap.get(entry.getKey());
            double value = entry.getValue();
            double result = value / count;
            avMap.put(entry.getKey(), df.format(result));
        }
        //封装项目newProjectsMap
        List<NewProjects> newProjects = newProjectsService.query();
        Map<String, NewProjects> newProjectsMap = new HashMap<>();
        for (NewProjects n : newProjects) {
            if (!newProjectsMap.containsKey(n.getSysId())) {
                newProjectsMap.put(n.getSysId(), n);
            }
        }
        //封装项目预警情况
        Map<String, EarlyWarningNode> earlyMap = new HashMap<>();
        List<EarlyWarningNode> earlyWarningNodeList = earlyWarningNodeService.query();
        for (EarlyWarningNode e : earlyWarningNodeList) {
            if (!earlyMap.containsKey(e.getNodeSysId())) {
                earlyMap.put(e.getNodeSysId(), e);
            }
        }
        int rows = 0;
        List<NodeNewschedulesDataModel> result = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            String projectName = "";
            String baseDetail = "";
            String nodeName = "";
            String planTime = "";
            String planBeginDate = "";
            String factTime = "";
            String factFinishDate = "";
            String avTime = "";         //节点平均用时
            String resUser = "";        //责任人
            String resUserPhone = "";    //责任人电话
            String operatorUser = "";   //经办人
            String operatorPhone = "";   //经办人电话
            String resDept = "";        //责任单位
            projectName = newProjectsMap.get(list.get(i).getProjectId()).getName();
            nodeName = list.get(i).getNodeName();
            String status = list.get(i).getStatus();
            if ("0".equals(status)) {
                if ("0".equals(list.get(i).getState())) {
                    baseDetail = "未确定";
                } else if ("1".equals(list.get(i).getState())) {
                    baseDetail = "未开始";
                } else if ("2".equals(list.get(i).getState())) {
                    baseDetail = "不需要";
                }
                planBeginDate = "";
                factTime = "0";
                factFinishDate = "";
            } else if ("1".equals(status)) {
                if ("0".equals(list.get(i).getState())) {
                    baseDetail = "未确定";
                } else if ("1".equals(list.get(i).getState())) {
                    baseDetail = "进行中";
                } else if ("2".equals(list.get(i).getState())) {
                    baseDetail = "不需要";
                }
                planBeginDate = list.get(i).getPlanBeginDate();
                factTime = "0";
                factFinishDate = "";
            } else if ("2".equals(status)) {
                if ("0".equals(list.get(i).getState())) {
                    baseDetail = "未确定";
                } else if ("1".equals(list.get(i).getState())) {
                    baseDetail = "已完成";
                } else if ("2".equals(list.get(i).getState())) {
                    baseDetail = "不需要";
                }
                planBeginDate = list.get(i).getPlanBeginDate();
                factTime = list.get(i).getFactTime();
                factFinishDate = list.get(i).getFactFinishDate();
            }
            planTime = list.get(i).getPlanTime();
            avTime = StringUtils.isNotBlank(avMap.get(list.get(i).getNodeId())) ? avMap.get(list.get(i).getNodeId()) : "";
            resUser = list.get(i).getResUser();
            resUserPhone = list.get(i).getResUserPhone();
            operatorUser = list.get(i).getOperatorUser();
            operatorPhone = list.get(i).getOperatorPhone();
            resDept = list.get(i).getResDept();
            EarlyWarningNode earlyWarningNode = earlyMap.get(list.get(i).getSysId());
            String earlyDays = "";      //逾期天数
            String messageNum = "";     //发送短信的次数

            if (ObjectUtils.isNotBlank(earlyWarningNode)) {
                //未处理的预警信息
                if ("0".equals(earlyWarningNode.getState())) {
                    earlyDays = earlyWarningNode.getNumber();
                    messageNum = earlyWarningNode.getMessageMumber();
                } else {
                    earlyDays = "";
                    messageNum = "";
                }
            }
            NodeNewschedulesDataModel nd = new NodeNewschedulesDataModel();
            nd.setProjectName(projectName);
            nd.setNodeName(nodeName);
            nd.setBaseDetail(baseDetail);
            nd.setPlanTime(planTime);
            nd.setFactTime(factTime);
            nd.setPlanBeginDate(planBeginDate);
            nd.setFactFinishDate(factFinishDate);
            nd.setAvTime(avTime);
            nd.setResUser(resUser);
            nd.setResUserPhone(resUserPhone);
            nd.setOperatorUser(operatorUser);
            nd.setOperatorPhone(operatorPhone);
            nd.setResDept(resDept);
            nd.setEarlyDays(earlyDays);
            nd.setMessageNum(messageNum);
            result.add(nd);
        }
        return result;
    }

    public List<NewProjectDataModel> queryProjectListData(NewProjectsFilter filter) {
        List<NewProjectDataModel> resultList = new ArrayList<>();
        List<NewProjects> newProjects = newProjectsService.getProjectInfoPage(filter);
        String sysId = "";                  //ID
        String projectName = "";            //项目名称
        String describes = "";             //基本情况
        String natureType = "";             //行业类别
        String startTime = "";              //开工时间
        String openState = "";              //开工状态
        String resDept = "";                //责任单位
        String ownerUnitPerson = "";         //负责人
        String ownerUnitPersonPhone = "";    //负责人电话
        String contactName = "";            //经办人
        String contactPhone = "";           //经办人电话
        String resUser = "";                //分管县领导
        String resPhone = "";               //分管县领导电话
        String address = "";                //项目地址
        String status = "";                 //进展情况
        String overdueNode = "";            //逾期节点
        String overSeeDeatil = "";          //督查情况
        for (int i = 0; i < newProjects.size(); i++) {
            NewProjectDataModel newProjectDataModel = new NewProjectDataModel();
            sysId = newProjects.get(i).getSysId();                  //ID
            projectName = newProjects.get(i).getName();            //项目名称
            describes = newProjects.get(i).getDescribes();             //基本情况
            String flag = newProjects.get(i).getNatureType();             //行业类别
            if ("0".equals(flag)) {
                natureType = "政府投资类";
            }
            if ("1".equals(flag)) {
                natureType = "企业投资类";
            }
            if ("2".equals(flag)) {
                natureType = "土地收储类";
            }
            if ("3".equals(flag)) {
                natureType = "政府投资房建市政类";
            }
            if ("4".equals(flag)) {
                natureType = "政府投资交通水利类";
            }
            String flag1 = newProjects.get(i).getStatus();              //开工时间
            if ("4".equals(flag1)) {
                startTime = newProjects.get(i).getStartTime();
                openState = "项目已完成";
            } else {
                startTime = newProjects.get(i).getStartTime();
                openState = "项目未开工";
            }
            resDept = newProjects.get(i).getResDept();                          //责任单位
            ownerUnitPerson = newProjects.get(i).getOwnerUnitPerson();           //负责人
            ownerUnitPersonPhone = newProjects.get(i).getOwnerUnitPersonPhone();    //负责人电话
            contactName = newProjects.get(i).getContactName();              //经办人
            contactPhone = newProjects.get(i).getContactPhone();            //经办人电话
            resUser = newProjects.get(i).getResUser();                      //分管县领导
            resPhone = newProjects.get(i).getResPhone();                    //分管县领导电话
            address = newProjects.get(i).getAddress();                      //项目地址
            String flag2 = newProjects.get(i).getStatus();                        //进展情况
            overdueNode = "";           //逾期节点
            overSeeDeatil = "";          //督查情况
            if ("0".equals(flag2)) {
                status = "项目创建成功";
            }
            if ("1".equals(flag2)) {
                status = "部门确认阶段";
            }
            if ("2".equals(flag2)) {
                status = "业主确认阶段";
            }
            if ("3".equals(flag2)) {
                status = "攻坚办审核，项目转进行中";
            }
            if ("4".equals(flag2)) {
                status = "项目审核完成";
            }
            newProjectDataModel.setSysId(sysId);
            newProjectDataModel.setProjectName(projectName);
            newProjectDataModel.setDescribes(describes);
            newProjectDataModel.setNatureType(natureType);
            newProjectDataModel.setStartTime(startTime);
            newProjectDataModel.setResDept(resDept);
            newProjectDataModel.setResUser(resUser);
            newProjectDataModel.setResPhone(resPhone);
            newProjectDataModel.setContactName(contactName);
            newProjectDataModel.setContactPhone(contactPhone);
            newProjectDataModel.setOwnerUnitPerson(ownerUnitPerson);
            newProjectDataModel.setOpenState(openState);
            newProjectDataModel.setOwnerUnitPersonPhone(ownerUnitPersonPhone);
            newProjectDataModel.setAddress(address);
            newProjectDataModel.setStatus(status);
            newProjectDataModel.setOverdueNode(overdueNode);
            newProjectDataModel.setOverSeeDeatil(overSeeDeatil);
            resultList.add(newProjectDataModel);
        }
        return resultList;
    }


    //=================导出绩效考核信息=======================

    public HSSFWorkbook getExcelGradePointListData(GradePointFilter filter, List<String> heads) {
        List<GradePoint> gradePoints;
        if (ObjectUtils.isBlank(filter.getSysIds())) {
            gradePoints = gradePointService.queryGradePoint(filter);
        } else {
            gradePoints = gradePointService.queryGradePointByIds(filter.getSysIds());
        }

        HSSFWorkbook wb = new HSSFWorkbook();//创建一个对应Excel文件
        HSSFSheet sheet = wb.createSheet("考核记录"); //床建excel 中的sheet
        HSSFRow row = sheet.createRow(0);
        sheet.autoSizeColumn(1, true);

        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式
        style.setFillForegroundColor((short) 13);// 设置背景色
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        //row.setHeight((short) 900);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        //------列-------
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(1, 1, 0, 0);
        sheet.addMergedRegion(cellRangeAddress0);
        HSSFCell cell1 = row.createCell(0);
        cell1.setCellValue("序号");
        cell1.setCellStyle(style);

        for (int i = 0; i < heads.size(); i++) {
            HSSFCell cell = row.createCell(i + 1);
            cell.setCellValue(GradePointHeaders.getValues(heads.get(i)).getValue());  //设置表头
            cell.setCellStyle(style);
            sheet.autoSizeColumn((short) i);
            sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 15 / 10);
        }

        String taskId = "";             //考核任务单号
        String checkType = "";          //考核类别
        String checkObject = "";        //考核对象
        String taskName = "";           //考核任务名
        String soucre = "";             //分数
        String rank = "";               //排名
        String taskContent = "";        //考核内容
        String updDate = "";            //考核更新时间
        int rows = 0;
        for (int i = 0; i < gradePoints.size(); i++) {
            taskId = gradePoints.get(i).getTaskId();
            checkType = gradePoints.get(i).getCheckType();
            checkObject = gradePoints.get(i).getCheckObject();
            taskName = gradePoints.get(i).getTaskName();
            soucre = gradePoints.get(i).getSoucre();
            rank = gradePoints.get(i).getRank();
            taskContent = gradePoints.get(i).getTaskContent();
            updDate = gradePoints.get(i).getUpdDate();

            rows++;
            row = sheet.createRow(rows);
            row.createCell(0).setCellValue(rows);
            for (int m = 0; m < heads.size(); m++) {
                if ("taskId".equals(GradePointHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(taskId);
                if ("checkType".equals(GradePointHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(checkType);
                if ("checkObject".equals(GradePointHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(checkObject);
                if ("taskName".equals(GradePointHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(taskName);
                if ("soucre".equals(GradePointHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(soucre);
                if ("rank".equals(GradePointHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(rank);
                if ("taskContent".equals(GradePointHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(taskContent);
                if ("updDate".equals(GradePointHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(updDate);
                sheet.autoSizeColumn((short) m);
                sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 15 / 10);
            }
        }
        return wb;
    }


    //=================导出绩效考核信息（汇总）=======================
    public HSSFWorkbook getExcelSummaryPointListData(ScoreSummaryFilter filter, List<String> heads) {
        String sheetName = "考核记录";
        List<ScoreSummary> scoreSummaries = new ArrayList<>();
        if (ObjectUtils.isBlank(filter.getSysIds())) {
            //判断是导出单位排名还是个人排名(true是单位排名)
            if (filter.isDepartRank()) {
                List<DepartRank> departRanks = scoreSummaryService.queryDepartRankNoPage(filter);
                int num = 1;
                for (DepartRank d : departRanks) {
                    ScoreSummary summary = new ScoreSummary();
//                    String strX = NumberUtils.keepPrecision(d.getScore(),2);
                    double x = (double) Math.round(d.getScore() * 100) / 100;
                    d.setScore(x);
                    d.setRank(num + "");
                    d.setCheckDept("——");

                    summary.setScore(x + "");
                    summary.setRank(num + "");
                    summary.setTypeRank(num + "");
                    summary.setCheckDept("——");
                    summary.setCheckObject(d.getCheckObject());
                    summary.setSysId(d.getSysId());
                    summary.setSummaryDate(d.getSummaryDate());
                    num++;
                    scoreSummaries.add(summary);
                }

            } else {
                scoreSummaries = scoreSummaryService.queryByFilterNoPage(filter);
            }
            if (StringUtils.isNotBlank(filter.getBranchType())) {
                for (ScoreSummary summary : scoreSummaries) {
                    summary.setRank(summary.getTypeRank());
                }
                if ("0".equals(filter.getBranchType())) {
                    sheetName = "业主单位考核汇总";
                }
                if ("1".equals(filter.getBranchType())) {
                    sheetName = "审批部门考核汇总";
                }
                if ("4".equals(filter.getBranchType())) {
                    sheetName = "督查组考核汇总";
                }
            }
        } else {
            scoreSummaries = scoreSummaryService.queryScoreSummaryByIds(filter.getSysIds());
        }

        HSSFWorkbook wb = new HSSFWorkbook();//创建一个对应Excel文件
        HSSFSheet sheet = wb.createSheet(sheetName); //床建excel 中的sheet
        HSSFRow row = sheet.createRow(0);
        sheet.autoSizeColumn(1, true);

        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式
        style.setFillForegroundColor((short) 13);// 设置背景色
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        //row.setHeight((short) 900);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        //------列-------
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(1, 1, 0, 0);
        sheet.addMergedRegion(cellRangeAddress0);

        for (int i = 0; i < heads.size(); i++) {
            HSSFCell cell = row.createCell(i + 1);
            cell.setCellValue(ScoreSummaryHeaders.getValues(heads.get(i)).getValue());  //设置表头
            cell.setCellStyle(style);
        }


        String sysId = "";              //考核任务单号
        String checkObject = "";        //考核对象
        String score = "";              //最终得分
        String rank = "";               //排名
        String checkDept = "";          //所属部门
        String summaryDate = "";        //汇总时间

        int rows = 0;
        for (int i = 0; i < scoreSummaries.size(); i++) {

            sysId = scoreSummaries.get(i).getSysId();                    //考核任务单号
            checkObject = scoreSummaries.get(i).getCheckObject();        //考核对象
            score = scoreSummaries.get(i).getScore();                    //最终得分
            rank = scoreSummaries.get(i).getRank();                      //排名
            checkDept = scoreSummaries.get(i).getCheckDept();            //所属部门
            summaryDate = scoreSummaries.get(i).getSummaryDate();        //汇总时间

            rows++;
            row = sheet.createRow(rows);
            row.createCell(0).setCellValue(rows);
            for (int m = 0; m < heads.size(); m++) {
                if ("sysId".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(sysId);
                if ("checkObject".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(checkObject);
                if ("score".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(score);
                if ("rank".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(rank);
                if ("checkDept".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(checkDept);
                if ("summaryDate".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(summaryDate);
            }
        }
        for (int m = 0; m < heads.size(); m++) {
            sheet.autoSizeColumn((short) m);
            sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 13 / 10);
        }
        return wb;
    }


    //=================导出绩效考核信息（汇总）（有时间段）=======================
    public HSSFWorkbook updateExcelSummaryPointListDataHaveTime(ScoreSummaryFilter filter, List<String> heads) {
        //查询成绩并将汇总成绩保存到临时表
        scoreSummaryService.saveSummaryScoreToTemp(filter);
        //更新分组排名
        tempService.updateSummaryScoreRank();


        String sheetName = "考核记录";
        List<ScoreSummaryTemp> scoreSummaries = new ArrayList<>();
        if (ObjectUtils.isBlank(filter.getSysIds())) {
            //判断是导出单位排名还是个人排名(true是单位排名)
            if (filter.isDepartRank()) {
                List<DepartRank> departRanks = scoreSummaryService.queryDepartRankNoPageInTime(filter);
                int num = 1;
                for (DepartRank d : departRanks) {
                    ScoreSummaryTemp summary = new ScoreSummaryTemp();
//                    String strX = NumberUtils.keepPrecision(d.getScore(),2);
                    double x = (double) Math.round(d.getScore() * 100) / 100;
                    d.setScore(x);
                    d.setRank(num + "");
                    d.setCheckDept("——");
                    summary.setScore(x + "");
                    summary.setRank(num + "");
                    summary.setTypeRank(num + "");
                    summary.setCheckDept("——");
                    summary.setCheckObject(d.getCheckObject());
                    summary.setSysId(d.getSysId());
                    summary.setSummaryDate(d.getSummaryDate());
                    num++;
                    scoreSummaries.add(summary);
                }
            } else {
                scoreSummaries = tempService.queryByFilterNoPage(filter);
                //个人
                Collections.sort(scoreSummaries, new Comparator<ScoreSummaryTemp>() {
                    @Override
                    public int compare(ScoreSummaryTemp o1, ScoreSummaryTemp o2) {
                        String val1 = o1.getScore();
                        Double valDouble1 = Double.parseDouble(val1);
                        String val2 = o2.getScore();
                        Double valDouble2 = Double.parseDouble(val2);
                        if (valDouble1 > valDouble2) {
                            return -1;
                        } else if (valDouble1 < valDouble2) {
                            return 1;
                        } else {
                            return 0;
                        }
                    }
                });
                int rank = 1;
                for (int i = 0; i < scoreSummaries.size(); i++) {
                    if (i == 0) {
                        scoreSummaries.get(i).setRank(rank + "");
                        rank++;
                    } else {
                        double currentValue = Double.parseDouble(StringUtils.isBlank(scoreSummaries.get(i).getScore()) ? "0.0" : scoreSummaries.get(i).getScore());
                        double preCurrentValue = Double.parseDouble(StringUtils.isBlank(scoreSummaries.get(i - 1).getScore()) ? "0.0" : scoreSummaries.get(i - 1).getScore());
                        if (currentValue == preCurrentValue) {
                            scoreSummaries.get(i).setRank(scoreSummaries.get(i - 1).getRank());
                            rank++;
                        } else {
                            scoreSummaries.get(i).setRank(rank + "");
                            rank++;
                        }
                    }

                    scoreSummaries.get(i).setSummaryDate(filter.getStartTime() + "至" + filter.getEndTime());
                }
            }
            if (StringUtils.isNotBlank(filter.getBranchType())) {
//                for (ScoreSummaryTemp summary : scoreSummaries) {
//                    summary.setRank(summary.getTypeRank());
//                }
                if ("0".equals(filter.getBranchType())) {
                    sheetName = "业主单位" + filter.getStartTime() + "至" + filter.getEndTime() + "考核汇总";
                }
                if ("1".equals(filter.getBranchType())) {
                    sheetName = "审批部门" + filter.getStartTime() + "至" + filter.getEndTime() + "考核汇总";
                }
                if ("4".equals(filter.getBranchType())) {
                    sheetName = "督查组" + filter.getStartTime() + "至" + filter.getEndTime() + "考核汇总";
                }
            }
        } else {
            scoreSummaries = tempService.queryScoreSummaryByIds(filter.getSysIds());
        }

        HSSFWorkbook wb = new HSSFWorkbook();//创建一个对应Excel文件
        HSSFSheet sheet = wb.createSheet(sheetName); //床建excel 中的sheet
        HSSFRow row = sheet.createRow(0);
        sheet.autoSizeColumn(1, true);

        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式
        style.setFillForegroundColor((short) 13);// 设置背景色
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        //row.setHeight((short) 900);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        //------列-------
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(1, 1, 0, 0);
        sheet.addMergedRegion(cellRangeAddress0);

        for (int i = 0; i < heads.size(); i++) {
            HSSFCell cell = row.createCell(i + 1);
            cell.setCellValue(ScoreSummaryHeaders.getValues(heads.get(i)).getValue());  //设置表头
            cell.setCellStyle(style);
        }


        String sysId = "";              //考核任务单号
        String checkObject = "";        //考核对象
        String score = "";              //最终得分
        String rank = "";               //排名
        String checkDept = "";          //所属部门
        String summaryDate = "";        //汇总时间

        int rows = 0;
        for (int i = 0; i < scoreSummaries.size(); i++) {

            sysId = scoreSummaries.get(i).getSysId();                    //考核任务单号
            checkObject = scoreSummaries.get(i).getCheckObject();        //考核对象
            score = scoreSummaries.get(i).getScore();                    //最终得分
            rank = scoreSummaries.get(i).getRank();                      //排名
            checkDept = scoreSummaries.get(i).getCheckDept();            //所属部门
            summaryDate = scoreSummaries.get(i).getSummaryDate();        //汇总时间

            rows++;
            row = sheet.createRow(rows);
            row.createCell(0).setCellValue(rows);
            for (int m = 0; m < heads.size(); m++) {
                if ("sysId".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(sysId);
                if ("checkObject".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(checkObject);
                if ("score".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(score);
                if ("rank".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(rank);
                if ("checkDept".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(checkDept);
                if ("summaryDate".equals(ScoreSummaryHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(summaryDate);
            }
        }
        for (int m = 0; m < heads.size(); m++) {
            sheet.autoSizeColumn((short) m);
            sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 13 / 10);
        }
        return wb;
    }


    public HSSFWorkbook getExcelTaskListData(SupervisionTaskFilter filter, List<String> heads, BnpUser bnpUser) {

//        String[] headArr = new String[]{"sysId","taskContent",
//                "tasktimes","overdueDays","planEndDate","taskResult",
//                "aaa001","groupType","inspectors","phones","resDept",
//                "operatorUser","operatorPhone","projectName","taskjobType",
//                "taskName","planStartDate","createDate","createTime","nodeId",
//                "nodeName","taskDate","startDate","endDate","supervisionScore",
//                "respScore","responseTime","respResult","supervisionResult",
//                "isfeedbackToTack","involveUnit"};

        filter.setUserinfo(bnpUser.getPhone());
        filter.setBranchType(bnpUser.getBranchType());
        filter.setRole(bnpUser.getRole());
        if (StringUtils.isBlank(filter.getGroupId())) {
            filter.setGroupId(bnpUser.getGroupCode());
        }
        String sheetName = "督查任务";
        List<SupervisionTask> taskList;
        if (ObjectUtils.isBlank(filter.getSysIds())) {
            taskList = taskService.getTaskListsNoPage(filter);
        } else {
            taskList = taskService.queryTasksByIds(filter.getSysIds());
        }

        HSSFWorkbook wb = new HSSFWorkbook();//创建一个对应Excel文件
        HSSFSheet sheet = wb.createSheet(sheetName); //床建excel 中的sheet
        HSSFRow row = sheet.createRow(0);
        sheet.autoSizeColumn(1, true);

        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式
        style.setFillForegroundColor((short) 13);// 设置背景色
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        //row.setHeight((short) 900);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        //------列-------
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(1, 1, 0, 0);
        sheet.addMergedRegion(cellRangeAddress0);

        for (int i = 0; i < heads.size(); i++) {
            HSSFCell cell = row.createCell(i + 1);
            cell.setCellValue(SupervisionTaskHeaders.getValues(heads.get(i)).getValue());  //设置表头
            cell.setCellStyle(style);
        }

        String sysId = "";              //任务单号
        String taskContent = "";              //督查事项详情
        String tasktimes = "";              //督查轮次
        String overdueDays = "";              //逾期天数
        String planEndDate = "";              //计划结束时间
        String taskResult = "";              //任务结果
        String aaa001 = "";              //任务状态
        String groupType = "";              //督查组别
        String inspectors = "";              //督查组成员
        String phones = "";              //督查组手机号
        String resDept = "";              //责任单位
        String operatorUser = "";              //责任单位经办人
        String operatorPhone = "";              //经办人手机号
        String projectName = "";              //项目名称
        String taskjobType = "";              //任务类别
        String taskName = "";              //任务名称
        String planStartDate = "";              //计划开始时间
        String createDate = "";              //创建日期
        String createTime = "";              //创建时间
        String nodeId = "";              //节点ID
        String nodeName = "";              //节点名称
        String taskDate = "";              //任务时间
        String startDate = "";              //开始日期
        String endDate = "";              //结束日期
        String supervisionScore = "";              //督查单位得分
        String respScore = "";              //责任单位得分
        String taskName1 = "";              //节点详情
        String planEndDate1 = "";              //到期日期
        String responseTime = "";              //响应时间
        String respResult = "";              //责任单位结果
        String supervisionResult = "";              //督查组结果
        String isfeedbackToTack = "";              //是否反馈攻坚
        String involveUnit = "";              //涉及部门

        int rows = 0;
        for (int i = 0; i < taskList.size(); i++) {
            sysId = taskList.get(i).getSysId();                    //任务单号
            taskContent = taskList.get(i).getTaskContent();                    //督查事项详情
            tasktimes = taskList.get(i).getTasktimes();                    //督查轮次
            overdueDays = taskList.get(i).getOverdueDays();                    //逾期天数
            planEndDate = taskList.get(i).getPlanEndDate();                    //计划结束时间
            taskResult = taskList.get(i).getTaskResult();                    //任务结果
            if ("1".equals(taskResult)) {
                taskResult = "已完成";
            } else if ("0".equals(taskResult)) {
                taskResult = "未完成";
            } else if ("3".equals(taskResult)) {
                taskResult = "已考核";
            } else if ("4".equals(taskResult)) {
                taskResult = "超时完成";
            } else {
                taskResult = "";
            }
            aaa001 = taskList.get(i).getAaa001();                    //任务状态
            if ("1".equals(aaa001)) {
                aaa001 = "有效任务";
            } else if ("0".equals(aaa001)) {
                aaa001 = "失效任务";
            } else {
                aaa001 = "";
            }
            groupType = taskList.get(i).getGroupType();                    //督查组别
            inspectors = taskList.get(i).getInspectors();                    //督查组成员
            phones = taskList.get(i).getPhones();                    //督查组手机号
            resDept = taskList.get(i).getResDept();                    //责任单位
            operatorUser = taskList.get(i).getOperatorUser();                    //责任单位经办人
            operatorPhone = taskList.get(i).getResPhone();                    //经办人手机号
            projectName = taskList.get(i).getProjectName();                    //项目名称
            taskjobType = taskList.get(i).getTaskjobType();                    //任务类别
            taskName = taskList.get(i).getTaskName();                    //任务名称
            planStartDate = taskList.get(i).getPlanStartDate();                    //计划开始时间
            createDate = taskList.get(i).getCreateDate();                    //创建日期
            createTime = taskList.get(i).getCreateTime();                    //创建时间
            nodeId = taskList.get(i).getNodeId();                    //节点ID
            nodeName = taskList.get(i).getNodeName();                    //节点名称
            taskDate = taskList.get(i).getTaskDate();                    //任务时间
            startDate = taskList.get(i).getStartDate();                    //开始日期
            endDate = taskList.get(i).getEndDate();                    //结束日期
            supervisionScore = taskList.get(i).getSupervisionScore();                    //督查单位得分
            respScore = taskList.get(i).getRespScore();                    //责任单位得分
            responseTime = taskList.get(i).getResponseTime();                    //响应时间
            respResult = taskList.get(i).getRespResult();                    //责任单位结果
            if ("1".equals(respResult)) {
                respResult = "已完成";
            } else if ("0".equals(respResult)) {
                respResult = "未完成";
            } else {
                respResult = "";
            }
            supervisionResult = taskList.get(i).getSupervisionResult();                    //督查组结果
            if ("1".equals(supervisionResult)) {
                supervisionResult = "已完成";
            } else if ("0".equals(supervisionResult)) {
                supervisionResult = "未完成";
            } else {
                supervisionResult = "";
            }
            isfeedbackToTack = taskList.get(i).getIsfeedbackToTack();                    //是否反馈攻坚
            involveUnit = taskList.get(i).getInvolveUnit();                    //涉及部门

            taskName1 = taskList.get(i).getTaskName();                    //节点详情
            planEndDate1 = taskList.get(i).getPlanEndDate();                    //到期日期


            rows++;
            row = sheet.createRow(rows);
            row.createCell(0).setCellValue(rows);
            for (int m = 0; m < heads.size(); m++) {
                if ("sysId".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(sysId);
                if ("taskContent".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(taskContent);
                if ("tasktimes".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(tasktimes);
                if ("overdueDays".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(overdueDays);
                if ("planEndDate".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(planEndDate);
                if ("taskResult".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(taskResult);
                if ("aaa001".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(aaa001);
                if ("groupType".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(groupType);
                if ("inspectors".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(inspectors);
                if ("phones".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(phones);
                if ("resDept".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(resDept);
                if ("operatorUser".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(operatorUser);
                if ("operatorPhone".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(operatorPhone);
                if ("projectName".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(projectName);
                if ("taskjobType".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(taskjobType);
                if ("taskName".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(taskName);
                if ("planStartDate".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(planStartDate);
                if ("createDate".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(createDate);
                if ("createTime".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(createTime);
                if ("nodeId".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(nodeId);
                if ("nodeName".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(nodeName);
                if ("taskDate".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(taskDate);
                if ("startDate".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(startDate);
                if ("endDate".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(endDate);
                if ("supervisionScore".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(supervisionScore);
                if ("respScore".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(respScore);
                if ("responseTime".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(responseTime);
                if ("respResult".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(respResult);
                if ("supervisionResult".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(supervisionResult);
                if ("isfeedbackToTack".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(isfeedbackToTack);
                if ("involveUnit".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(involveUnit);

                if ("taskName1".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(taskName1);
                if ("planEndDate1".equals(SupervisionTaskHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(planEndDate1);
            }
        }
        for (int m = 0; m < heads.size(); m++) {
            sheet.autoSizeColumn((short) m);
            sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 13 / 10);
        }
        return wb;
    }


    public HSSFWorkbook getExcelMessageListData(MessageFilter filter, List<String> heads) {

        String sheetName = "消息列表";
        List<Message> messageList;
        if (ObjectUtils.isBlank(filter.getSysIds())) {
            messageList = messageService.getMessageInfoNoPage(filter);
        } else {
            messageList = messageService.queryMessageByIds(filter.getSysIds());
        }

        HSSFWorkbook wb = new HSSFWorkbook();//创建一个对应Excel文件
        HSSFSheet sheet = wb.createSheet(sheetName); //床建excel 中的sheet
        HSSFRow row = sheet.createRow(0);
        sheet.autoSizeColumn(1, true);

        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式
        style.setFillForegroundColor((short) 13);// 设置背景色
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        //row.setHeight((short) 900);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        //------列-------
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(1, 1, 0, 0);
        sheet.addMergedRegion(cellRangeAddress0);

        for (int i = 0; i < heads.size(); i++) {
            HSSFCell cell = row.createCell(i + 1);
            cell.setCellValue(MessageHeaders.getValues(heads.get(i)).getValue());  //设置表头
            cell.setCellStyle(style);
        }
        String projectName = "";    //消息名称
        String type = "";           //类别
        String resDept = "";        //收件单位
        String recipients = "";     //收件人
        String phone = "";          //电话号码
        String text = "";           //短信内容
        String createDate = "";     //日期
        String createTime = "";     //时间
        int rows = 0;
        for (int i = 0; i < messageList.size(); i++) {
            projectName = messageList.get(i).getProjectName();
            type = messageList.get(i).getType();

            if ("0".equals(type)) {
                type = "节点确认";
            } else if ("1".equals(type)) {
                type = "任务开始";
            } else if ("2".equals(type)) {
                type = "逾期短信";
            } else if ("3".equals(type)) {
                type = "即将到期";
            } else {
                type = "督查任务";
            }
            resDept = messageList.get(i).getResDept();
            recipients = messageList.get(i).getRecipients();
            phone = messageList.get(i).getPhone();
            text = messageList.get(i).getText();
            createDate = messageList.get(i).getCreateDate();
            createTime = messageList.get(i).getCreateTime();
            rows++;
            row = sheet.createRow(rows);
            row.createCell(0).setCellValue(rows);
            for (int m = 0; m < heads.size(); m++) {
                if ("projectName".equals(MessageHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(projectName);
                if ("type".equals(MessageHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(type);
                if ("resDept".equals(MessageHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(resDept);
                if ("recipients".equals(MessageHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(recipients);
                if ("phone".equals(MessageHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(phone);
                if ("text".equals(MessageHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(text);
                if ("createDate".equals(MessageHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(createDate);
                if ("createTime".equals(MessageHeaders.getValues(heads.get(m)).getCode()))
                    row.createCell(m + 1).setCellValue(createTime);
            }
        }
        for (int m = 0; m < heads.size(); m++) {
            sheet.autoSizeColumn((short) m);
            sheet.setColumnWidth(m, sheet.getColumnWidth(m) * 13 / 10);
        }
        return wb;
    }

    /**
     * 提供项目id 返回这些项目的计划时间
     *
     * @param allProjects
     * @return
     * @throws ParseException
     */
    public List<NodeNewschedulesModel> iii(List<String> allProjects) throws ParseException {
        List<NodeNewschedulesModel> list = new ArrayList<>();
        for (String project : allProjects) {
            List<NodeNewschedulesModel> models = new ArrayList<>();
            List<NodeNewschedules> nodeList = nns.getNodeByProjectIdAndState(project, "");
            Map<String, Object> preOfNodeMap = new TreeMap<>();
            for (NodeNewschedules n : nodeList) {
                //筛选确定的节点
                if ("1".equals(n.getState())) {
                    //大节点
                    if ("1".equals(n.getType())) {
                        if (!preOfNodeMap.containsKey(n.getNodeId())) {
                            preOfNodeMap.put(n.getNodeId(), n.getPreNodeId());
                        }
                    } else {
                        //小节点
                        if (!preOfNodeMap.containsKey(n.getNodeId())) {
                            preOfNodeMap.put(n.getNodeId(), preOfNodeMap.get(n.getNodeIds()));
                        }
                    }
                }
            }
            for (NodeNewschedules n : nodeList) {
                NodeNewschedulesModel m = new NodeNewschedulesModel();
                //对象复制n->m
                BeanUtils.copyProperties(n, m);
                models.add(m);
            }
            //推算计划时间
            models = planTimeReckonService.reckonPlanTime(models, preOfNodeMap);
            for (NodeNewschedulesModel m : models) {
                list.add(m);
            }
        }
        return list;
    }

}
